﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;

namespace Auction_Boxing_2
{
    public class StateInvalnerable : State
    {
        GameTimer Period;
        float WaitInterval = 1;
        float Interval = 1000;

        Animation Stopped;
        Animation Moving;

        public StateInvalnerable(State state)
        {
            StateName = "moving";
            this.ATextures = state.StatePlayer.ATextures;

            Period = new GameTimer(WaitInterval, Interval);

            LoadState(state.StatePlayer, ATextures);



        }

        public override void LoadState(BoxingPlayer player, Dictionary<string, Animation> ATextures)
        {
            this.StatePlayer = player;
            this.PlayerAnimation = ATextures[StateName];
            this.Stopped = ATextures["stopped"];
            this.Moving = ATextures["moving"];

            this.speed = new Vector2(Tools.speedCalc(StatePlayer.MaxMovement), Tools.Y_SCALE * Tools.speedCalc(StatePlayer.MaxMovement));

            StatePlayer.isAttacking = false;
            StatePlayer.isHit = false;

            StatePlayer.Hurtbox = Rectangle.Empty;

            Period.Start();
        }

        public override void Initialize()
        {

        }

        public override void HandleMovement()
        {

            if (StatePlayer.KeysDown.Contains(KeyPressed.Up) && !StatePlayer.KeysDown.Contains(KeyPressed.Right) && !StatePlayer.KeysDown.Contains(KeyPressed.Left))
                Translate(0, -speed.Y);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Down) && !StatePlayer.KeysDown.Contains(KeyPressed.Right) && !StatePlayer.KeysDown.Contains(KeyPressed.Left))
                Translate(0, speed.Y);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Right) && !StatePlayer.KeysDown.Contains(KeyPressed.Up) && !StatePlayer.KeysDown.Contains(KeyPressed.Down))
                Translate(speed.X, 0);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Left) && !StatePlayer.KeysDown.Contains(KeyPressed.Up) && !StatePlayer.KeysDown.Contains(KeyPressed.Down))
                Translate(-speed.X, 0);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Up) && StatePlayer.KeysDown.Contains(KeyPressed.Right))
                Translate(speed.X, -speed.Y);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Up) && StatePlayer.KeysDown.Contains(KeyPressed.Left))
                Translate(-speed.X, -speed.Y);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Down) && StatePlayer.KeysDown.Contains(KeyPressed.Right))
                Translate(speed.X, speed.Y);

            if (StatePlayer.KeysDown.Contains(KeyPressed.Down) && StatePlayer.KeysDown.Contains(KeyPressed.Left))
                Translate(-speed.X, speed.Y);

        }

        public override void HandleDirection()
        {

            if (StatePlayer.KeysDown.Contains(KeyPressed.Right) && !StatePlayer.KeysDown.Contains(KeyPressed.Left))
                StatePlayer.PlayerEffect = SpriteEffects.None;
            if (StatePlayer.KeysDown.Contains(KeyPressed.Left) && !StatePlayer.KeysDown.Contains(KeyPressed.Right))
                StatePlayer.PlayerEffect = SpriteEffects.FlipHorizontally;


        }

        public override void Update(GameTime gameTime)
        {
            if (StatePlayer.KeysDown.Contains(KeyPressed.Up) || StatePlayer.KeysDown.Contains(KeyPressed.Right) || StatePlayer.KeysDown.Contains(KeyPressed.Left) || StatePlayer.KeysDown.Contains(KeyPressed.Right))
                this.PlayerAnimation = Moving;
            else
                this.PlayerAnimation = Stopped;
        }

        public override void HandleState()
        {
            if (!Period.Enabled)
                StatePlayer.InternalState = new StateMoving(this);

            else if (StatePlayer.CurrentHealth <= 0)
                StatePlayer.InternalState = new StateDead(this);

            else if (StatePlayer.KeysDown.Contains(KeyPressed.Up) && StatePlayer.DblJumpTimer.Active)
                StatePlayer.InternalState = new StateJumping(StatePlayer.direction, this);

        }

        public override void Translate(float x, float y)
        {


        }

        public override void HandleCollision(List<BoxingPlayer> Players)
        {

        }


    }


}
